/*
 * Copyright 2005-2013 biz-united. All rights reserved.
 * Support: http://www.biz-united.com.cn
 * License: http://www.biz-united.com.cn/?page_id=5&act=3
 */
package net.biz.dao.impl;

import java.util.Date;

import javax.persistence.FlushModeType;
import javax.persistence.Query;

import org.apache.commons.lang.time.DateUtils;
import org.springframework.stereotype.Repository;

import net.biz.dao.CartDao;
import net.biz.entity.Cart;
/**
 * Dao - 购物车
 * 
 * @author BIZ Team
 * @version 3.0
 */
@Repository("cartDaoImpl")
public class CartDaoImpl extends BaseDaoImpl<Cart, Long> implements CartDao {

	
	public void evictExpired() {
		String jpql = "delete from Cart cart where cart.modifyDate <= :expire";
		entityManager.createQuery(jpql).setFlushMode(FlushModeType.COMMIT).setParameter("expire", DateUtils.addSeconds(new Date(), -Cart.TIMEOUT)).executeUpdate();
	}
	
	public int updateCart(Long cartId){
		String sql=" update xx_cart_item set is_submit=0 where cart=:cartId";
		Query query = entityManager.createNativeQuery(sql);
		query.setParameter("cartId", cartId);
		int i=query.executeUpdate();
		return i;
	}

}